const mongoose = require('mongoose');
const shortid = require('shortid');
const moment = require('moment');


const LikeSchema = new mongoose.Schema({
    _id: {
        type: String,
        default: shortid.generate,
        unique: true//主键
    },
    good_id:{
        type:String,
        ref:'Good'
    },
    king_id:{
        type:String,
        ref:'Buller'
    }


})
LikeSchema.statics = {
    getLikeById: (id,king_id, callback) => {
        Like.findOne({'good_id': id,'king_id':king_id}).then(function (good) {
            callback(null, good);
        }).catch(function (err) {
            callback(err);
        })
    },
    getLikesByKing:(id,callback)=>{
        Like.find({'king_id': id}).populate('good_id').then(function (goods) {
            callback(null, goods);
        }).catch(function (err) {
            callback(err);
        })
    }

}

const Like = mongoose.model('like', LikeSchema);
module.exports = Like;
